package com.yuanlrc.school.controller;

import com.github.pagehelper.PageInfo;
import com.yuanlrc.school.common.config.MySysUser;
import com.yuanlrc.school.entity.StudentDB;
import com.yuanlrc.school.entity.StudentVO;
import com.yuanlrc.school.service.TchSelStuExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class TchSelStuName {

    @Autowired
    private TchSelStuExamService tchSelStuExamService;

//    @RequestMapping("/tchSelStuClass")
//    @ResponseBody
//    public String tchSelStuClass(Model model){
//        String tid= MySysUser.loginName();
//        Map jsonObject = new JSONObject();
//        List<Map> tchClass = tchSelStuExamService.selTchClass(tid);
//        model.addAttribute("tchClass",tchClass);
//
//        return "view/teacher/selStuName";
//    }

    @RequestMapping("/tchSelStuClass")
    public String tchSelStuClass(){
        return "view/teacher/selStuName";
    }

    @RequestMapping("/tchSelStu")
    @ResponseBody
    public Object tchSelStu(Integer page, Integer limit, StudentVO studentVO){
        String tid= MySysUser.loginName();
        List<StudentDB> tchStu = tchSelStuExamService.selTchByStu(studentVO);
        Map<String, Object> tableData = new HashMap<String, Object>();
//        StringBuffer snames = new StringBuffer();
//        boolean bool = false;
//        for (StudentDB stu: tchStu) {
//            if (bool){
//                snames.append(",");
//            }
//            snames.append(stu.getSname());
//            bool = true;
//        }
//        String[] names = snames.toString().split(",");
//        int i = (int)(Math.random()*names.length);

        PageInfo pageInfo = new PageInfo(tchStu);
//        String name = names[i];
//        System.out.println(names);
        tableData.put("code", 0);
        tableData.put("msg", "");
//        tableData.put("stuName",name);
        tableData.put("data",pageInfo.getList());
        return tableData;
    }
}
